import com.google.appengine.api.datastore.*
import static com.google.appengine.api.datastore.FetchOptions.Builder.*
 
// query the scripts stored in the datastore
def query = new Query("Concello")
 
query.addSort("numeroItems", Query.SortDirection.DESCENDING)
query.addFilter("numeroItems", Query.FilterOperator.GREATER_THAN, 0)
 
PreparedQuery preparedQuery = datastore.prepare(query)
 
// return only the first 20 results
def entities = preparedQuery.asList( withLimit(5) )

html.ol {
	
	entities.eachWithIndex {concello,i->
	if (concello) {	
	
		li(class:"top5 clearfix") {
			a(class:'post_link',href:"/concello/${concello.key?.id}") {
				span class:'top5_number' ,"${i+1}"
				
				div(class:'top-follow-list') {
					em("Concello de ${concello.nome}")
					div(class:'top-follow-meta') {
						div(class:'category-meta') {
							p {
								strong("Paisanos: ${concello.numeroPaisanos?:'0'}")
							}
							p {
								span("Novidades: ${concello.numeroItems}")
							}
						}
					}				
					
				}
			}
		}
	
	}
	} //fin each
}


